package com.cykj.controller;


import com.alibaba.fastjson.JSON;
import com.cykj.dto.ResponseDTO;
import com.cykj.entity.AdminDO;
import com.cykj.entity.MenuDO;
import com.cykj.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Objects;

@RestController
@RequestMapping("/menu")
public class MenuController {


    @Autowired
    private IMenuService menuService;

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    // 请求路径： 127.0.0.1:8080/jd-admin-service/menu/tree
    // 获取树形菜单
    @GetMapping("/tree")
    public ResponseDTO getMenuTree(String token) {
        Object adminDO = redisTemplate.opsForValue().get(token);
        AdminDO adminInfo = JSON.parseObject(Objects.requireNonNull(adminDO).toString(), AdminDO.class);
        return menuService.getTreeMenus(adminInfo.getRoleId());
    }

}
